/**
 * Created with JetBrains WebStorm.
 * User: Administrator
 * Date: 6/29/12
 * Time: 11:46 AM
 * To change this template use File | Settings | File Templates.
 */
/**
 */

/**
 * Graphics namespace
 * @namespace Graphics
 *
 */
if (typeof Graphics == "undefined" || !Graphics){
    var Graphics = {};
}

/**
 * Render tex into the canvas context.
 * Compatible with FF3.5, SF4, GC4, OP10
 *
 * @method Graphics.drawText
 * @static
 */
Graphics.drawText = function(g, txt, font, x, y, col) {
    g.save();
    if (col) g.strokeStyle = col;
    g.font = font;
    g.strokeText(txt, x, y);
    g.restore();
};

/**
 * Render center text into the canvas context.
 * @method Graphics.centerDrawText
 * @static
 */
Graphics.centerDrawText  = function(g, txt, font, y, col){
    g.save();
    if (col)g.strokeStyle = col;
    g.font = font;
    g.strokeText(txt, (GameHandler.width - g.measureText(txt).width)/2, y);
    g.restore();
}

Graphics.fillText = function(g, txt, font, x, y, col){
    g.save();
    if (col) g.fillStyle = col;
    g.font = font;
    g.strokeText(txt, x, y);
    g.restore();
}

Graphics.centerFillText = function(g, txt, font, y, col){
    g.save();
    if (col) g.fillStyle = col;
    g.font = font;
    g.strokeText(txt, (GameHandler.width - g.measureText(txt).width)/2, y);
    g.restore();
}

/**
 * render textbox into canvas context
 */
Graphics.drawTextBox = function(g, txt, xpos, ypos, wpos, hpos, cborder, ctext){
    g.save();
    g.fillStyle = ctext;
    g.strokeStyle = cborder;
    g.fillText(txt, xpos + 10, ypos + 10);
    g.strokeRect(xpos, ypos, wpos, hpos);
    g.restore();
}

/**
 * function for render image with offset, postion
 */

Graphics.renderImage = function(ctx, image, offx, offy, sw, sh, xpos, ypos, dw, dh){
    ctx.drawImage(image, offx, offy, sw, sh, xpos, ypos, dw, dh);
}
